
<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<style type="text/css">
    input[type="checkbox"], input[type="radio"] {
    cursor: pointer;
    height: 15px;
    left: -9999px;
    opacity: 1;
    position: static;
    width: 15px;
    z-index: 12;
}
</style>
<!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="/luckydog/index">首页</a>
                        </li>
                        <li class="active">
                            <a href="#">角色管理</a>
                        </li>
                        <li class="active">
                            <a href="/luckydog/role/rolelist">角色列表</a>
                        </li>
                        <li class="active">
                            编辑角色
                        </li>
                    </ul>
                </div>
                <div class="page-body">
                    <div class="row">
                        <div class="col-xs-12 col-md-12">
                            <div class="tab-content tabs-flat no-padding">
                                <div id="visits" class="tab-pane active animated fadeInUp">
                                    <div class="row">
                                        <form   method="POST" id="theForm"  target="_parent" style="padding:20px; 20px;" >
                                            <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">
                                                角色名称：
                                            </div>
                                            <div style="float: left; padding-left:10px;">
                                                <input class="form-control pull-left" value="<?=$roleInfo['name']?>" style="width:120px;" placeholder="请输入角色名称" id="rolename" type="text">
                                            </div>
                                            <?php foreach ($roleList as $key => $menu):?>
                                            <table width="90%"  height="30" border="0" cellpadding=0 cellspacing=0  class="table table-border">
                                                <tr>
                                                    <td>
                                                        <table width="90%"   cellpadding=0 cellspacing=0 class="noborder"  >
                                                            <tr>
                                                                <td height="26" valign="center"  rowspan="2" scope="col" class="Ziyuan_next" >
                                                                    <input type="checkbox" class="title_td" <?php if(isset($roleInfo['power'][$menu['role']])):?> checked="checked"<?php endif;?>   name="<?= $menu['role']?>"  ><?= $menu['name']?>
                                                                </td>
                                                                <?php foreach ($menu['child'] as $childkey => $child):?>
                                                                    <?php if($childkey <= 1):?>
                                                                    <td class="actClass"><input  <?php if(isset($roleInfo['power'][$menu['role']]) && in_array($child['role'],$roleInfo['power'][$menu['role']])):?> checked="checked"<?php endif;?> type="checkbox" name="<?= $child['role']?>"class="<?= $menu['role']?>_next"  ><?= $child['name']?></td>
                                                                    <?php endif;?>
                                                                <?php endforeach;?>
                                                            </tr>
                                                            <tr>
                                                                <?php foreach ($menu['child'] as $childkey => $child):?>
                                                                <?php if($childkey > 1):?>
                                                                    <td class="actClass"><input <?php if(isset($roleInfo['power'][$menu['role']]) && in_array($child['role'],$roleInfo['power'][$menu['role']])):?> checked="checked"<?php endif;?> type="checkbox" name="<?= $child['role']?>"class="<?= $menu['role']?>_next"  ><?= $child['name']?></td>
                                                                <?php endif;?>
                                                                <?php endforeach;?>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                            <?php endforeach;?>
                                            <input type="hidden" value="<?= $gropuID?>" id="gropuID" />
                                        </form>
                                        <table width="90%" style="margin-left: 27px;margin-bottom: 50px;">
                                            <tr>
                                                <td class="none">
                                                    <input type="checkbox" class="all" />全选
                                                    <input type="button" class="btn btn-success submit" value="保存" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->
<script src="<?php echo STATICURL; ?>js/jquery-2.0.3.min.js"></script>
<script src="<?php echo STATICURL; ?>layer/layer.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script type="text/javascript">
    $(document).ready(function(){
        $('.all').click(function(){
            if($(this).prop("checked")){
                $("#theForm").find("input[type='checkbox']").prop('checked',true);
            }else{
                $("#theForm").find("input[type='checkbox']").attr('checked',false);
            }
        });

        $('.title_td').on("click", function(){
            var _this_table = $(this).parent().parent().parent();
            if($(this).prop("checked")){
                _this_table.find("input[type='checkbox']").prop("checked",true);
            }else{
                _this_table.find("input[type='checkbox']").attr('checked',false);
            }
        });

        $('.submit').click(function(){
            var rolename = $('#rolename').val();
            var gropuID = $('#gropuID').val();
            if(rolename == ""){
                layer.msg("请添加角色名");return false;
            }
            var powerstr  = "";
            var stip = "";
            $('.title_td').each(function(){
                if(true == $(this).prop("checked")){
                    powerstr += stip + $(this).attr('name')+":"+ find_next( $(this).attr('name') );
                    stip = "|";
                }
            })
            if(confirm("确定要编辑角色吗？"))
            {
                $.post("/luckydog/role/systemPowerSet",{powerstr:powerstr,rolename:rolename,gropuID:gropuID},function(res)
                {
                    if(res)
                    {
                        layer.msg("成功");
                        window.location.href="/luckydog/role/rolelist";
                    }else{
                        layer.msg("失败");
                    }
                    
                },"json");
            }
        });
        function find_next( tip ){
            var cla = "."+tip+"_next";
            var str = ''; var stip = "";
            $(cla).each(function(){
                if( true == $(this).prop("checked")){
                    str += stip + $(this).attr('name')+"*";
                    stip = "-";
                }
            })
            return str;
        }
    })
    
</script>





